package com.fingard.dsp.bank.directbank.boc01;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.bankInterface.IElecBillTrans;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.*;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.detail.*;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

/*
* 开发完成
* */
public class BOC01ElecBillTrans  extends  BOC01Base implements IElecBillTrans{

    @Override
//    通用签收	b2e0109 已测
    public RetAtsB003BillRespSubmit D_B003_BillResp_Submit(ReqB003BillRespSubmit query) throws Exception {
        //通用签收接口调整 b2e0279
        return receiveBill(query);

//        RetAtsB003BillRespSubmit retAts = new RetAtsB003BillRespSubmit(query.reqHeader);
//        retAts.writeStart();
//        String reqSeqID = "";
//
//        try{
//            BOC01Header bankHeader = new BOC01Header();
//            bankHeader.trncod = "b2e0109";//交易代码
//            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
//            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
//
//            writeCommonHeader(xmlWriter, bankHeader);
//            xmlWriter.writeStartElement("trn-b2e0109-rq");
//            xmlWriter.writeElementString("ceitinfo","");
//            while(query.readRecord()){
//                reqSeqID = query.detail.reqSeqID;
//                xmlWriter.writeStartElement("b2e0109-rq");
//                xmlWriter.writeElementString("ibknum","");  //联行号，可空
//                xmlWriter.writeElementString("actacn",query.detail.actNum);
//                xmlWriter.writeElementString("msgseq",getBankSeq(query.detail.billNo));
//                if("1".equals(query.detail.respFlag)) {
//                    xmlWriter.writeElementString("bacflg", "SU00");  //SU00同意签收 SU01拒绝签收
//                }
//                else{
//                    xmlWriter.writeElementString("bacflg", "SU01");
//                }
//                xmlWriter.writeElementString("memo",query.detail.memo);
//                xmlWriter.writeEndElement();
//            }
//            xmlWriter.writeEndDocument();
//            if (bankFront.lastVisitTime != null) {
//                long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
//                if (timeSpan < 5000l) {
//                    long sleepMils = 5000l - timeSpan;
//                    this.WriteBankLogLn2("sleep(" + sleepMils + ")");
//                    Thread.sleep(5000l - timeSpan);
//                }
//            }
//            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
//            if(retStrArr[0].length() == 0) {
//                StringBuilder tmpSbMsg = new StringBuilder();
//                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
//                if (tmpBkReader != null) {
//                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
//                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
//                    String obssid = tmpBkReader.getSimpleText("obssid");
//                    if (isActiveRetCode(tmpRetCode)){
//                        RetAtsB003BillRespSubmitDetail detail  = new RetAtsB003BillRespSubmitDetail();
//                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0109-rs/b2e0109-rs/status")){
//                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
//                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
//                                detail.respCode = "0";
//                                detail.respInfo = EachRespInfo;
//                                detail.transState =  EachRespCode;
//                                detail.payInfoCode = EachRespCode;
//                                detail.reqSeqID = reqSeqID;
//                                retAts.writeDetail(detail);
//
//                                saveBankReq(obssid,reqSeqID);
//                            }
//                        }
//                    }
//                    else{
//                        retAts.writeRespCode("-1");
//                        retAts.writeRespInfo(tmpRetInfo);
//                    }
//                }
//                else{
//                    retAts.writeRespCode("-1");
//                    retAts.writeRespInfo(tmpSbMsg.toString());
//                }
//            }
//            else{
//                retAts.writeRespCode("-1");
//                retAts.writeRespInfo(retStrArr[1]);
//            }
//        }
//        catch (Exception ex){
//            ex.printStackTrace();
//        }
//
//        retAts.writeEnd();
//        return retAts;
    }

    @Override
//    出票	b2e0101
    public RetAtsB101BillApplySubmit D_B101_BillResp_Submit(ReqB101BillApplySubmit query) throws Exception {
        RetAtsB101BillApplySubmit retAts = new RetAtsB101BillApplySubmit(query.reqHeader);
        retAts.writeStart();
        try{
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0101";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0101-rq");
            xmlWriter.writeElementClosed("ceitinfo");
            while(query.readRecord()){
                xmlWriter.writeStartElement("b2e0101-rq");
                xmlWriter.writeElementString("insid",query.detail.reqSeqID);   //指令ID,唯一
                if("1".equals(query.detail.billType)){
                    //AC01银行承兑汇票； AC02商业承兑汇票
                    xmlWriter.writeElementString("drafttype","AC01");
                }
                else{
                    xmlWriter.writeElementString("drafttype","AC02");
                }

                xmlWriter.writeStartElement("drawee");
//                xmlWriter.writeElementString("ibknum", query.detail.drawBnkCode);
                String drawBnkCode = getElecBillBranchConfig().getMapValueByKey("RecBankNo",query.detail.drawBnkCode);
                xmlWriter.writeElementString("ibknum", drawBnkCode);
//                xmlWriter.writeElementString("ibknum", query.detail.dircDrawBnkCode);
                xmlWriter.writeElementString("actacn",query.detail.drawAct);
                xmlWriter.writeElementString("actnam ",query.detail.drawName);
                xmlWriter.writeEndElement();
                xmlWriter.writeStartElement("toactn");
                if(query.detail.payeeAct.length()==18&&"1".equals(query.detail.payeeSameBnk)) {
//                    String payeeCaps = getBankConfig().getMapValueByKey("bankCaps",query.detail.payeeBnkCode);
//                    xmlWriter.writeElementString("ibknum",payeeCaps );
                    String recBankNo = getElecBillBranchConfig().getMapValueByKey("RecBankNo",query.detail.payeeBnkCode);
                    xmlWriter.writeElementString("ibknum",recBankNo);
                }else{
                    xmlWriter.writeElementString("ibknum", query.detail.payeeBnkCode);
                }
                xmlWriter.writeElementString("actacn",query.detail.payeeAct);
                xmlWriter.writeElementString("actnam",query.detail.payeeName);
                xmlWriter.writeEndElement();
                xmlWriter.writeStartElement("acceptor");
                xmlWriter.writeElementString("ibknum",query.detail.accpBnkCode);
                if("1".equals(query.detail.billType)) {
                    xmlWriter.writeElementString("actacn","0");
                }else{
                    xmlWriter.writeElementString("actacn", query.detail.accpAct);
                }
                xmlWriter.writeElementString("actnam",query.detail.accpName);
//                xmlWriter.writeElementString("actacn","101824419587");
//                xmlWriter.writeElementString("actnam","沙河市通源经贸有限公司(测试)");
                xmlWriter.writeEndElement();

                xmlWriter.writeElementString("bookdate","");
                xmlWriter.writeElementString("duedate", Format.Date8Format.format(Format.DateTimeFormat.parse(query.detail.dueDate)));
                xmlWriter.writeElementString("amount",query.detail.billAmt);
                if(query.detail.transFlag.equals("1")) {
                    xmlWriter.writeElementString("transferflg", "EM00"); //EM00可以转让；EM01禁止转让
                }
                else{
                    xmlWriter.writeElementString("transferflg", "EM01");
                }
                xmlWriter.writeElementString("memo",query.detail.memo);
                String autoPrompt = getBankConfig().getValueAsString("AutoAcceptOrReceipt");
                if(StringHelper.hasAnyChar(autoPrompt)
                        &&(StringHelper.isNullOrEmpty(query.detail.autoPromptAccept)||"0".equals(query.detail.autoPromptAccept))
                        &&(StringHelper.isNullOrEmpty(query.detail.autoPromptReceipt)||"0".equals(query.detail.autoPromptReceipt))){
                    if(autoPrompt.toLowerCase().equals("accept")) {
                        query.detail.autoPromptAccept ="1";
                    } else if(autoPrompt.toLowerCase().equals("receipt")){
                        query.detail.autoPromptReceipt ="1";
                    }
                }
                //自动提示收票，ats不兼容，暂时调整为不支持自动提示收票
                if("1".equals(query.detail.autoPromptAccept)) {
                    xmlWriter.writeElementString("autoacp", "1");
                    xmlWriter.writeElementString("autorec", "0");
                }else if("1".equals(query.detail.autoPromptReceipt)) {
                    xmlWriter.writeElementString("autoacp", "1");
                    xmlWriter.writeElementString("autorec", "1");
                }else{
                    xmlWriter.writeElementString("autoacp", "0");
                    xmlWriter.writeElementString("autorec", "0");
                }
                xmlWriter.writeEndElement();
            }

            xmlWriter.writeEndDocument();
            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String reqSeqID  = tmpBkReader.getSimpleText("insid");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB101BillApplySubmitDetail detail  = new RetAtsB101BillApplySubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0101-rs/b2e0101-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode ;
                                detail.payInfoCode = EachRespCode ;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);
                                saveBankReq(obssid,reqSeqID);
//                            }
//                            else{
//                                detail.respCode = EachRespCode;
//                                detail.respInfo = EachRespInfo;
//                                detail.transState =  tmpRetCode ;
//                                detail.payInfoCode = tmpRetCode ;
//                                detail.reqSeqID = reqSeqID;
//                                retAts.writeDetail(detail);
//                            }
                        }
                    }else {
                        RetAtsB101BillApplySubmitDetail detail = new RetAtsB101BillApplySubmitDetail();
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeEnd();
        return retAts;
    }

    @Override
//    提示承兑	b2e0105
    public RetAtsB102BillAccpSubmit D_B102_BillResp_Submit(ReqB102BillAccpSubmit query) throws Exception {
        RetAtsB102BillAccpSubmit retAts = new RetAtsB102BillAccpSubmit(query.reqHeader);
        retAts.writeStart();
        try {
            String reqSeqID = "";
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0105";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0105-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0105-rq");
                xmlWriter.writeElementString("ibknum","");
                xmlWriter.writeElementString("actacn",query.detail.actNum);
                xmlWriter.writeElementString("draftno",query.detail.billNo);
                xmlWriter.writeElementString("comnum","");
                xmlWriter.writeElementString("invnum","");
                xmlWriter.writeElementString("memo",query.detail.memo);
                xmlWriter.writeEndElement();
            }

            xmlWriter.writeEndDocument();
            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB102BillAccpSubmitDetail detail  = new RetAtsB102BillAccpSubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0105-rs/b2e0105-rs")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("status/rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("status/rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);
                                
                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    }else {
                        RetAtsB102BillAccpSubmitDetail detail = new RetAtsB102BillAccpSubmitDetail();
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeEnd();
        return retAts;
    }

    @Override
//    撤票	b2e0104
    public RetAtsB103BillRetSubmit D_B103_BillResp_Submit(ReqB103BillRetSubmit query) throws Exception {
        RetAtsB103BillRetSubmit retAts = new RetAtsB103BillRetSubmit(query.reqHeader);
        retAts.writeStart();
        String reqSeqID = "";
        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0104";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0104-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0104-rq");
                xmlWriter.writeElementString("ibknum","");
                xmlWriter.writeElementString("actacn",query.detail.actNum);
                xmlWriter.writeElementString("draftno",query.detail.billNo);
                xmlWriter.writeEndElement();
            }

            xmlWriter.writeEndDocument();

            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB103BillRetSubmitDetail detail  = new RetAtsB103BillRetSubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0104-rs/b2e0104-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);
                                
                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    }else {
                        RetAtsB103BillRetSubmitDetail detail = new RetAtsB103BillRetSubmitDetail();
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeEnd();
        return retAts;
    }

    @Override
//    提示收票	b2e0108 已测
    public RetAtsB104BillReceSubmit D_B104_BillResp_Submit(ReqB104BillReceSubmit query) throws Exception {
        RetAtsB104BillReceSubmit retAts = new RetAtsB104BillReceSubmit(query.reqHeader);
        retAts.writeStart();
        String reqSeqID = "";
        try{
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0108";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0108-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0108-rq");
                xmlWriter.writeElementString("ibknum","");  //联行号，可空
                xmlWriter.writeElementString("actacn",query.detail.actNum);
                xmlWriter.writeElementString("draftno",query.detail.billNo);
                xmlWriter.writeElementString("memo",query.detail.memo);
                xmlWriter.writeEndElement();
            }
            xmlWriter.writeEndDocument();

            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB104BillReceSubmitDetail detail  = new RetAtsB104BillReceSubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0108-rs/b2e0108-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);
                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    } else {
                        RetAtsB104BillReceSubmitDetail detail = new RetAtsB104BillReceSubmitDetail();
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }

        retAts.writeEnd();
        return retAts;
    }

    @Override
//    背书转让申请	b2e0280
    public RetAtsB105BillEndoSubmit D_B105_BillResp_Submit(ReqB105BillEndoSubmit query) throws Exception {
        RetAtsB105BillEndoSubmit retAts = new RetAtsB105BillEndoSubmit(query.reqHeader);
        retAts.writeStart();
        String reqSeqID = "";
        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0280";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0280-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0280-rq");
                xmlWriter.writeStartElement("account");
                xmlWriter.writeElementString("ibknum","");
                xmlWriter.writeElementString("actacn",query.detail.actNum);
                xmlWriter.writeEndElement();
                xmlWriter.writeElementString("draftno",query.detail.billNo);
                xmlWriter.writeStartElement("endorseinfo");
                xmlWriter.writeElementString("cnaps",query.detail.receBnkCode);
                //被背书人帐号
                xmlWriter.writeElementString("actacn",query.detail.receAct);
                xmlWriter.writeElementString("actnam ",query.detail.receName);
                xmlWriter.writeEndElement();
                if(query.detail.transFlag.equals("1")) {
                    //EM00可以转让；EM01禁止转让
                    xmlWriter.writeElementString("transferflg", "EM00");
                }
                else{
                    xmlWriter.writeElementString("transferflg", "EM01");
                }
                xmlWriter.writeElementString("memo",query.detail.memo);
                xmlWriter.writeEndElement();
            }

            xmlWriter.writeEndDocument();

            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB105BillEndoSubmitDetail detail  = new RetAtsB105BillEndoSubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0280-rs/b2e0280-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);

                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    }else {
                        RetAtsB105BillEndoSubmitDetail detail  = new RetAtsB105BillEndoSubmitDetail();
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeEnd();
        return retAts;
    }

    @Override
//    贴现申请	b2e0110 已测
    public RetAtsB106BillDiscSubmit D_B106_BillResp_Submit(ReqB106BillDiscSubmit query) throws Exception {
        RetAtsB106BillDiscSubmit retAts = new RetAtsB106BillDiscSubmit(query.reqHeader);
        retAts.writeStart();
        String reqSeqID = "";
        RetAtsB106BillDiscSubmitDetail detail  = new RetAtsB106BillDiscSubmitDetail();
        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0110";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0110-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                 reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0110-rq");
                xmlWriter.writeStartElement("account");
                xmlWriter.writeElementString("ibknum","");
                xmlWriter.writeElementString("actacn",query.detail.actNum);
                xmlWriter.writeEndElement();
                xmlWriter.writeElementString("draftno",query.detail.billNo);
                if("1".equals(query.detail.discType)) {
                    xmlWriter.writeElementString("rdstyp", "RM00");
                }else{
                    throw new Exception("银行只支持买断式贴现！");
                }

                BigDecimal discRate = new BigDecimal(query.detail.discRate);
                discRate = discRate.divide(new BigDecimal(100));
                xmlWriter.writeElementString("rdsrat",discRate.toString());
                xmlWriter.writeElementString("bookdate","");
                if(query.detail.payType.equals("1")) {
                    xmlWriter.writeElementString("onlflg", "SM00");
                }
                else{
                    xmlWriter.writeElementString("onlflg","SM01");
                }
                if("1".equals(query.detail.discType)) {
                    xmlWriter.writeElementString("opndat", "");
                    xmlWriter.writeElementString("duedat", "");
                    xmlWriter.writeElementString("redrat", "");
                    xmlWriter.writeElementString("redamt", "");
                }else{
                    xmlWriter.writeElementString("opndat", DateHelper.convertD10toD8(query.detail.repOpenDate));
                    xmlWriter.writeElementString("duedat", DateHelper.convertD10toD8(query.detail.repDueDate));
                    BigDecimal repRate = new BigDecimal(query.detail.repRate);
                    repRate = repRate.divide(new BigDecimal(100));
                    xmlWriter.writeElementString("redrat", repRate.toString());
                    xmlWriter.writeElementString("redamt", query.detail.repAmt);
                }
                xmlWriter.writeElementString("comnum","");
                xmlWriter.writeElementString("invnum","");
                xmlWriter.writeElementString("memo",query.detail.memo);
                if("2".equals(query.detail.payInterestType)) {
                    xmlWriter.writeElementString("ratscl", "100");
                    xmlWriter.writeElementString("bustyp", "1");
                }else if("3".equals(query.detail.payInterestType)){
                    xmlWriter.writeElementString("ratscl", query.detail.payInterestRate);
                    xmlWriter.writeElementString("bustyp", "1");
                }else{
                xmlWriter.writeElementString("ratscl","");
                xmlWriter.writeElementString("bustyp","");
                }
                xmlWriter.writeStartElement("entry");
                //ecds检测贴现涉及3家机构会报错，入账账号可以传贴现行号，银行转钱的时候根据入账账号可以分析出开户行
                xmlWriter.writeElementString("toibkn",query.detail.receBnkCode);
                xmlWriter.writeElementString("actacn",query.detail.actedAct);
                xmlWriter.writeEndElement();

                xmlWriter.writeStartElement("inman");
                xmlWriter.writeElementString("inibkn",query.detail.receBnkCode);
                xmlWriter.writeElementString("inactn",query.detail.receAct);
                xmlWriter.writeElementString("incnam",query.detail.receName);
                xmlWriter.writeEndElement();

                xmlWriter.writeEndElement();
            }

            xmlWriter.writeEndDocument();

            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0110-rs/b2e0110-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    }else {
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    detail.respCode = "-1";
                    detail.respInfo = tmpSbMsg.toString();
                }
            }
            else{
                detail.respCode = "-1";
                detail.respInfo = retStrArr[1];
            }
        }
        catch (Exception ex){
            detail.respCode = "-1";
            detail.respInfo = ex.getMessage();
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    @Override
//    质押申请	b2e0285
    public RetAtsB107BillPledSubmit D_B107_BillResp_Submit(ReqB107BillPledSubmit query) throws Exception {
        RetAtsB107BillPledSubmit retAts = new RetAtsB107BillPledSubmit(query.reqHeader);
        retAts.writeStart();
        String reqSeqID = "";
        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0285";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0285-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0285-rq");
                xmlWriter.writeStartElement("account");
                xmlWriter.writeElementString("ibknum","");
                xmlWriter.writeElementString("actacn",query.detail.actNum);
                xmlWriter.writeEndElement();
                xmlWriter.writeElementString("draftno",query.detail.billNo);
                xmlWriter.writeStartElement("pawninfo");
                xmlWriter.writeElementString("cnaps",query.detail.receBnkCode);
                xmlWriter.writeElementString("actacn",query.detail.receAct);
                xmlWriter.writeElementString("actnam",query.detail.receName);
                xmlWriter.writeEndElement();

                xmlWriter.writeElementString("memo",query.detail.memo);
                xmlWriter.writeEndElement();
            }

            xmlWriter.writeEndDocument();

            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB107BillPledSubmitDetail detail  = new RetAtsB107BillPledSubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0285-rs/b2e0285-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);
                                
                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    }else{
                        RetAtsB107BillPledSubmitDetail detail = new RetAtsB107BillPledSubmitDetail();
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeEnd();
        return retAts;
    }

    @Override
//    提示付款	b2e0111 已测
    public RetAtsB108BillPaySubmit D_B108_BillResp_Submit(ReqB108BillPaySubmit query) throws Exception {
        RetAtsB108BillPaySubmit retAts = new RetAtsB108BillPaySubmit(query.reqHeader);
        retAts.writeStart();
        String reqSeqID  = "";
        try{
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0111";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0111-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0111-rq");
                xmlWriter.writeElementString("ibknum","");  //联行号，可空
                xmlWriter.writeElementString("actacn",query.detail.actNum);
                xmlWriter.writeElementString("draftno",query.detail.billNo);
                xmlWriter.writeElementString("bookdate","");
                xmlWriter.writeElementString("amount",query.detail.billAmt);
                if(query.detail.payType.equals("1")) {
                    xmlWriter.writeElementString("onlflg", "SM00");
                }
                else{
                    xmlWriter.writeElementString("onlflg","SM01");
                }
                if("1".equals(query.detail.proPayType)) {
                    xmlWriter.writeElementString("overduereason", "");
                }else{
                    xmlWriter.writeElementString("overduereason",query.detail.overDueRea);
                }
                xmlWriter.writeElementString("memo",query.detail.memo);
                xmlWriter.writeEndElement();
            }
            xmlWriter.writeEndDocument();

            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB108BillPaySubmitDetail detail  = new RetAtsB108BillPaySubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0111-rs/b2e0111-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);
                                
                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    }else{
                        RetAtsB108BillPaySubmitDetail detail = new RetAtsB108BillPaySubmitDetail();
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }

        retAts.writeEnd();
        return retAts;
    }

    @Override
//    保证申请	b2e0281
    public RetAtsB109BillGuarSubmit D_B109_BillResp_Submit(ReqB109BillGuarSubmit query) throws Exception {
        RetAtsB109BillGuarSubmit retAts = new RetAtsB109BillGuarSubmit(query.reqHeader);
        retAts.writeStart();
        String reqSeqID = "";
        try{
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0281";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0281-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0281-rq");
                xmlWriter.writeStartElement("account");
                xmlWriter.writeElementString("ibknum","");  //联行号，可空
                xmlWriter.writeElementString("actacn",query.detail.actNum);
                xmlWriter.writeEndElement();
                if(query.detail.guarType.equals("1")) {
                    xmlWriter.writeElementString("transtype", "B1");   //B1:出票保证申请 B2:承兑保证申请 B3:背书保证申请
                }
                else if(query.detail.guarType.equals("2")){
                    xmlWriter.writeElementString("transtype", "B2");
                }
                else{
                    xmlWriter.writeElementString("transtype", "B3");
                }
                xmlWriter.writeElementString("draftno",query.detail.billNo);
                xmlWriter.writeStartElement("assureinfo");
                xmlWriter.writeElementString("cnaps",query.detail.receBnkCode);
                xmlWriter.writeElementString("actacn",query.detail.receAct);
                xmlWriter.writeElementString("actnam",query.detail.receName);
                xmlWriter.writeEndElement();

                xmlWriter.writeElementString("memo",query.detail.memo);
                xmlWriter.writeEndElement();
            }
            xmlWriter.writeEndDocument();

            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB109BillGuarSubmitDetail detail  = new RetAtsB109BillGuarSubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0281-rs/b2e0281-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);
                                
                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    }
                    else{
                        retAts.writeRespCode("-1");
                        retAts.writeRespInfo(tmpRetInfo);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }

        retAts.writeEnd();
        return retAts;
    }

    @Override
//    追索通知	b2e0282
    public RetAtsB110BillRecoSubmit D_B110_BillResp_Submit(ReqB110BillRecoSubmit query) throws Exception {
        RetAtsB110BillRecoSubmit retAts = new RetAtsB110BillRecoSubmit(query.reqHeader);
        retAts.writeStart();
        String reqSeqID = "";
        try{
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0282";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0282-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0282-rq");
                xmlWriter.writeStartElement("account");
                xmlWriter.writeElementString("ibknum","");  //联行号，可空
                xmlWriter.writeElementString("actacn",query.detail.actNum);
                xmlWriter.writeEndElement();
                xmlWriter.writeElementString("draftno",query.detail.billNo);
                xmlWriter.writeStartElement("troverinfo");
                xmlWriter.writeElementString("tramt",query.detail.recourseAmt);
                if("1".equals(query.detail.recourseType)) {
                    xmlWriter.writeElementString("trtyp", "RT00");
                    xmlWriter.writeElementString("trreason","");
                }
                else{
                    xmlWriter.writeElementString("trtyp", "RT01");
                    if("1".equals(query.detail.recourseCode)){
                        xmlWriter.writeElementString("trreason","RC00");
                    }else{
                        xmlWriter.writeElementString("trreason","RC01");
                    }
                }
                xmlWriter.writeEndElement();

                xmlWriter.writeStartElement("btrinfo");
//                if(StringHelper.hasAnyChar(query.detail.receCode)) {
//                    xmlWriter.writeElementString("btrporg", query.detail.receCode);
//                }else{
//                    xmlWriter.writeElementString("btrporg", "571965762");
//                }
//                if(StringHelper.hasAnyChar(query.detail.receBnkCode)) {
//                    xmlWriter.writeElementString("cnaps",query.detail.receBnkCode);
//                }else{
//                    xmlWriter.writeElementString("cnaps","104584000003");
//                }
//                if(StringHelper.hasAnyChar(query.detail.receAct)) {
//                    xmlWriter.writeElementString("actacn",query.detail.receAct);
//                }else{
//                    xmlWriter.writeElementString("actacn","762758040684");
//                }
//                if(StringHelper.hasAnyChar(query.detail.recoName)) {
//                    xmlWriter.writeElementString("actnam",query.detail.recoName);
//                }else{
//                    xmlWriter.writeElementString("actnam","测试企业5");
//                }
                xmlWriter.writeElementString("btrporg",query.detail.recourseCode);
                xmlWriter.writeElementString("cnaps",query.detail.recoBnkCode);
                xmlWriter.writeElementString("actacn",query.detail.receAct);
                xmlWriter.writeElementString("actnam",query.detail.recoName);
                xmlWriter.writeEndElement();

                xmlWriter.writeElementString("memo",query.detail.memo);
                xmlWriter.writeEndElement();
            }
            xmlWriter.writeEndDocument();

            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB110BillRecoSubmitDetail detail  = new RetAtsB110BillRecoSubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0282-rs/b2e0282-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);
                                
                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    }else {
                        RetAtsB110BillRecoSubmitDetail detail = new RetAtsB110BillRecoSubmitDetail();
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }

        retAts.writeEnd();
        return retAts;
    }

    @Override
//    同意清偿	b2e0112
    public RetAtsB111BillAgreeSubmit D_B111_BillResp_Submit(ReqB111BillAgreeSubmit query) throws Exception {
        RetAtsB111BillAgreeSubmit retAts = new RetAtsB111BillAgreeSubmit(query.reqHeader);
        retAts.writeStart();
        String reqSeqID = "";
        try {
//            BOC01Header bankHeader = new BOC01Header();
//            bankHeader.trncod = "b2e0112";//交易代码
//            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
//            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
//
//            writeCommonHeader(xmlWriter, bankHeader);
//            xmlWriter.writeStartElement("trn-b2e0112-rq");
//            xmlWriter.writeElementString("ceitinfo","");
//            while(query.readRecord()){
//                reqSeqID = query.detail.reqSeqID;
//                xmlWriter.writeStartElement("b2e0112-rq");
//                xmlWriter.writeElementString("ibknum","");
//                xmlWriter.writeElementString("actacn",query.detail.actNum);
//                xmlWriter.writeElementString("msgseq",getBankSeq(query.detail.billNo));
//                xmlWriter.writeElementString("bacflg","SU00");
//                xmlWriter.writeElementString("rfucod","");
//                xmlWriter.writeElementString("rfumemo","");
//                xmlWriter.writeElementString("memo",query.detail.memo);
//                xmlWriter.writeEndElement();
//            }
            BOC01Header bankHeader = new BOC01Header();
            //交易代码
            bankHeader.trncod = "b2e0279";
            //报文编号 字母数字串 0-12位
            bankHeader.trnid = getQryTransID();
            //发银行报文的XML对象
            XmlTextWriter xmlWriter = new XmlTextWriter();

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0279-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0279-rq");
                xmlWriter.writeStartElement("account");
                //联行号，可空
                xmlWriter.writeElementString("ibknum","");
                xmlWriter.writeElementString("actacn",query.detail.actNum);
                xmlWriter.writeEndElement();
                xmlWriter.writeElementString("transtype","H3");
                xmlWriter.writeElementString("msgseq",query.detail.busiNo);
                if("1".equals(query.detail.respFlag)) {
                    //SU00同意签收 SU01拒绝签收
                    xmlWriter.writeElementString("bacflg", "SU00");
                }
                else{
                    xmlWriter.writeElementString("bacflg", "SU01");
                }
                xmlWriter.writeElementString("memo",query.detail.memo);
                xmlWriter.writeElementString("asaddr","");
                xmlWriter.writeElementString("uncpro","");
                xmlWriter.writeElementString("agrno","");
                xmlWriter.writeElementString("rfucod","");
                xmlWriter.writeElementString("rfumemo","");
                xmlWriter.writeElementString("amount",query.detail.agreeAmt);
                xmlWriter.writeEndElement();
            }

            xmlWriter.writeEndDocument();
            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB111BillAgreeSubmitDetail detail  = new RetAtsB111BillAgreeSubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0279-rs/b2e0279-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);
                                
                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    }else {
                        RetAtsB111BillAgreeSubmitDetail detail = new RetAtsB111BillAgreeSubmitDetail();
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeEnd();
        return retAts;
    }

    @Override
//    交易撤回	b2e0106
    /*
    * A3承兑申请撤回 A7提示收票撤回 D2贴现申请撤回 F2提示付款申请撤回 B4保证申请撤回 C2转让撤回
      E2质押申请撤回 E5质权解除申请撤回 H2:追索通知撤回 H4同意清偿撤回
    * */
    public RetAtsB112BillCancSubmit D_B112_BillResp_Submit(ReqB112BillCancSubmit query) throws Exception {
        RetAtsB112BillCancSubmit retAts = new RetAtsB112BillCancSubmit(query.reqHeader);
        retAts.writeStart();
        String reqSeqID = "";
        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0106";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0106-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0106-rq");
                xmlWriter.writeElementString("ibknum","");
                xmlWriter.writeElementString("actacn",query.detail.actNum);
//                xmlWriter.writeElementString("msgseq",getBankSeq(query.detail.billNo));
                xmlWriter.writeElementString("msgseq",query.detail.busiNo);
                /*
                    撤回类型 1-承兑申请撤回 2-提示收票申请撤回 3-背书转让申请撤回 4-贴现申请撤回 5-质押申请撤回 6-（逾期）提示付款撤回
    7-出票保证申请撤回 8-承兑保证申请撤回  9-背书保证申请撤回 10-追索通知撤回 11-同意清偿撤回 12-解质押申请撤回
                * */
                if("1".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","A3");
                }
                else if("2".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","A7");
                }
                else if("3".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","C2");
                }
                else if("4".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","D2");
                }
                else if("5".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","E2");
                }
                else if("6".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","F2");
                }
                else if("7".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","B4");
                }
                else if("8".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","B4");
                }
                else if("9".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","B4");
                }
                else if("10".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","H2");
                }
                else if("11".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","H4");
                }
                else if("12".equals(query.detail.cancelType)){
                    xmlWriter.writeElementString("transtype","E5");
                }

                xmlWriter.writeEndElement();
            }

            xmlWriter.writeEndDocument();

            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB112BillCancSubmitDetail detail  = new RetAtsB112BillCancSubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0106-rs/b2e0106-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);
                                
                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    }else {
                        RetAtsB112BillCancSubmitDetail detail = new RetAtsB112BillCancSubmitDetail();
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeEnd();
        return retAts;
    }

    @Override
    public RetAtsB113ProtocolSubmit D_B113_ProtocolResp_Submit(ReqB113ProtocolSubmit query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB119BillRelePledSubmit D_B119_BillResp_Submit(ReqB119BillRelePledSubmit query) throws Exception {
        RetAtsB119BillRelePledSubmit retAts = new RetAtsB119BillRelePledSubmit(query.reqHeader);
        retAts.writeStart();
        RetAtsB119BillRelePledSubmitDetail detail = new RetAtsB119BillRelePledSubmitDetail();
        query.readRecord();
        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0286";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0286-rq");
            xmlWriter.writeElementString("ceitinfo","");
            xmlWriter.writeStartElement("b2e0286-rq");
//                <account>		客户账户信息
            xmlWriter.writeStartElement("account");
//            <ibknum>	联行号	可空数字 5位
            xmlWriter.writeElementString("ibknum","");
//            <actacn>	账号		非空数码 1-32位
            xmlWriter.writeElementString("actacn",query.detail.actNum);
            xmlWriter.writeEndElement();
//               <draftno>		票据号码	非空数码 1- 30位
            xmlWriter.writeElementString("draftno",query.detail.billNo);
//               <memo>		质权人备注	可空字符0-256位
            xmlWriter.writeElementString("memo",query.detail.memo);
            xmlWriter.writeEndDocument();
            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000l) {
                        long sleepMils = 5000l - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000l - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0286-rs/b2e0286-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){    //返回码未确定
                            detail.respCode = "0";
                            detail.respInfo = EachRespInfo;
                            detail.transState =  EachRespCode;
                            detail.payInfoCode = EachRespCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            retAts.writeDetail(detail);
                            saveBankReq(obssid, detail.reqSeqID);
//                            }
                        }
                    }else {
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = query.detail.reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeEnd();
        return retAts;
    }


    /**
     * @param query
     * @return
     * @throws Exception
     * 通用签收接口 b2e0279
     */
    public RetAtsB003BillRespSubmit receiveBill(ReqB003BillRespSubmit query) throws Exception {
        RetAtsB003BillRespSubmit retAts = new RetAtsB003BillRespSubmit(query.reqHeader);
        retAts.writeStart();
        String reqSeqID = "";

        try{
            BOC01Header bankHeader = new BOC01Header();
            //交易代码
            bankHeader.trncod = "b2e0279";
            //报文编号 字母数字串 0-12位
            bankHeader.trnid = getQryTransID();
            //发银行报文的XML对象
            XmlTextWriter xmlWriter = new XmlTextWriter();

            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0279-rq");
            xmlWriter.writeElementString("ceitinfo","");
            while(query.readRecord()){
                reqSeqID = query.detail.reqSeqID;
                xmlWriter.writeStartElement("b2e0279-rq");
                xmlWriter.writeStartElement("account");
                //联行号，可空
                xmlWriter.writeElementString("ibknum","");
                xmlWriter.writeElementString("actacn",query.detail.actNum);
                xmlWriter.writeEndElement();
                String transType = getTransCode(query);
                xmlWriter.writeElementString("transtype",transType);
                xmlWriter.writeElementString("msgseq",query.detail.busiNo);
                if("1".equals(query.detail.respFlag)) {
                    //SU00同意签收 SU01拒绝签收
                    xmlWriter.writeElementString("bacflg", "SU00");
                }
                else{
                    xmlWriter.writeElementString("bacflg", "SU01");
                }
                xmlWriter.writeElementString("memo",query.detail.memo);
                xmlWriter.writeElementString("asaddr","");
                if("1".equals(query.detail.respType)) {
                    //中行必须传承诺兑付
                    if("1".equals(query.detail.respFlag)&&"1".equals(query.detail.mustPay)) {
                        xmlWriter.writeElementString("uncpro", "CC00");
                    }else if("2".equals(query.detail.respFlag)){
                        xmlWriter.writeElementString("uncpro", "CC00");
                    }else{
                        throw new Exception("提示承兑同意签收时，到期无条件支付承诺只能传【CC00】!");
                    }
                    xmlWriter.writeElementString("agrno",query.detail.protocolNo);

                }else{
                    xmlWriter.writeElementString("uncpro", "");
                    xmlWriter.writeElementString("agrno","");
                }
                if("6".equals(query.detail.respType)&&"2".equals(query.detail.respFlag)) {
                    if(StringHelper.isNullOrEmpty(query.detail.unPayCode)){
                        throw new Exception("提示付款拒签时，拒付理由不能为空!");
                    }
                    if("99".equals(query.detail.unPayCode)){
                        xmlWriter.writeElementString("rfucod", "DC09");
                        xmlWriter.writeElementString("rfumemo",query.detail.unPayMemo);
                    }else{
                        xmlWriter.writeElementString("rfucod", "DC0" + (Integer.valueOf(query.detail.unPayCode) - 1));
                        xmlWriter.writeElementString("rfumemo", "");
                    }
                }else{
                    xmlWriter.writeElementString("rfucod", "");
                    xmlWriter.writeElementString("rfumemo","");
                }
                xmlWriter.writeElementString("amount","");
                xmlWriter.writeEndElement();
            }
            xmlWriter.writeEndDocument();

            //是否需要和前一次请求保持5秒的间隔
            boolean isNeedWait  = isNeedWaitFiveS();
            if(isNeedWait) {
                if (bankFront.lastVisitTime != null) {
                    long timeSpan = -bankFront.lastVisitTime.getTime() + new Date().getTime();
                    if (timeSpan < 5000L) {
                        long sleepMils = 5000L - timeSpan;
                        this.WriteBankLogLn2("sleep(" + sleepMils + ")");
                        Thread.sleep(5000L - timeSpan);
                    }
                }
            }
            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            if(retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getSimpleText("rspcod");
                    String tmpRetInfo = tmpBkReader.getSimpleText("rspmsg");
                    String obssid = tmpBkReader.getSimpleText("obssid");
                    if (isActiveRetCode(tmpRetCode)){
                        RetAtsB003BillRespSubmitDetail detail  = new RetAtsB003BillRespSubmitDetail();
                        while(tmpBkReader.read("/bocb2e/trans/trn-b2e0279-rs/b2e0279-rs/status")){
                            String EachRespCode = tmpBkReader.readedXElement.getSingleText("rspcod");
                            String EachRespInfo = tmpBkReader.readedXElement.getSingleText("rspmsg");
//                            if(bankRetRightCode.equals(EachRespCode)){
                                detail.respCode = "0";
                                detail.respInfo = EachRespInfo;
                                detail.transState =  EachRespCode;
                                detail.payInfoCode = EachRespCode;
                                detail.reqSeqID = reqSeqID;
                                retAts.writeDetail(detail);

                                saveBankReq(obssid,reqSeqID);
//                            }
                        }
                    }else {
                        RetAtsB003BillRespSubmitDetail detail = new RetAtsB003BillRespSubmitDetail();
                        detail.respCode = "0";
                        detail.respInfo = tmpRetInfo;
                        detail.transState =  tmpRetCode;
                        detail.payInfoCode = tmpRetCode;
                        detail.reqSeqID = reqSeqID;
                        retAts.writeDetail(detail);
                    }
                }
                else{
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());
                }
            }
            else{
                retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1]);
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }

        retAts.writeEnd();
        return retAts;
    }

    private String getTransCode(ReqB003BillRespSubmit query){
        //    应答类型 1-承兑应答 2-收票应答 3-背书转让应答 4-回购式贴现赎回应答 5-质押解除应答 6-提示付款应答 7-保证应答 8-同意清偿应
        //    A4=承兑确认 A8=收票确认 C3=被背书人签收 B5=保证确认 E3=质押确认 E6=质押解除确认 G1=票据付款确认 H3=同意清偿确认 H5=收到清偿确认
        String retStr  = "";
        if("1".equalsIgnoreCase(query.detail.respType)){retStr = "A4";}
        else if("2".equalsIgnoreCase(query.detail.respType)){retStr ="A8";}
        else if("3".equalsIgnoreCase(query.detail.respType)){retStr = "C3";}
        else if("4".equalsIgnoreCase(query.detail.respType)){retStr = "";}
        else if("5".equalsIgnoreCase(query.detail.respType)){retStr = "E6";}
        else if("6".equalsIgnoreCase(query.detail.respType)){retStr = "G1";}
        else if("7".equalsIgnoreCase(query.detail.respType)){retStr = "B5";}
        else if("8".equalsIgnoreCase(query.detail.respType)){retStr = "H5";}
        else if("9".equalsIgnoreCase(query.detail.respType)){retStr = "E3";}
        return retStr;
    }

}
